import 'babel-polyfill';
import inquirer from 'inquirer';
import co from 'co';
import test from './service/test';

// 注册service
const service = {
    1: test,
};

// 退出
function quit() {
    process.exit();
}

// 检验
function validate() {
    return (value) => {
        const valid = value !== '';
        return valid || '不能为空';
    };
}

// 选项
const options = [
    {
        type: 'list',
        name: 'opt',
        message: '你需要哪些服务?',
        choices: [
            { name: '生成支付宝二维码', value: 1 },
        ],
        validate: validate(),
    },
];

function main() {
    co(function* f() {
        const choice = yield inquirer.prompt(options);

        yield service[choice.opt]();

        quit();
    });
}

// 开始
main();
